package com.sf.web.controller;

import com.sf.domain.Employee;
import com.sf.service.IEmployeeService;
import com.sf.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/employees")
public class EmployeeController {
    @Autowired
    private IEmployeeService iEmployeeService;

    @GetMapping

    public JsonResult list(){
        return new JsonResult(true,"操作成功",iEmployeeService.list());
    }

    @PostMapping

    public JsonResult save(Employee employee){
        iEmployeeService.insert(employee);
        return new JsonResult(true,"操作成功",null);
    }

    @PutMapping

    public JsonResult update(Employee employee,Long id){
        iEmployeeService.update(employee,id);
        return new JsonResult(true,"操作成功",null);
    }
    @DeleteMapping

    public JsonResult delete(Long id){
        iEmployeeService.delete(id);
        return new JsonResult(true,"操作成功",null);
    }
    @GetMapping
    public JsonResult get(Long id){
        iEmployeeService.get(id);
        return new JsonResult(true,"操作成功",iEmployeeService.get(id));
    }
}
